Skip to content

Fix against se-0184a #1247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2017
Merged

Fix against se-0184a #1247

merged 1 commit into from
Nov 18, 2017

Conversation

tayloraswift
Copy link
Member

Patch for SE 0184a

@@ -38,8 +38,8 @@ open class Host: NSObject {
static internal func currentHostName() -> String {
let hname = UnsafeMutablePointer<Int8>.allocate(capacity: Int(NI_MAXHOST))
defer {
hname.deinitialize()
hname.deallocate(capacity: Int(NI_MAXHOST))
hname.deinitialize(count: 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've always found this method confusing. What does it actually do?

https://developer.apple.com/documentation/swift/unsafemutablepointer/1641720-deinitialize is no help, it just says that deinitialize() deinitializes! Does it zero the memory, for example? I assume not otherwise the documentation would say so.

If it is just changing the "state" of the memory then I question the meaning/utility of the "states".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ianpartridge Isn't deinitialize for objects where the deinit method is called on them? If Im correct its not needed for arrays of Int8

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I think this is unrelated to deinit which only applies to classes. UnsafeMutablePointer et al are structs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to the type stored in the allocated memory not the UnsafeMutablePointer itself.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see what you mean, sorry :) If that's correct then the doc doesn't mention it!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deinitialize does nothing for trivial types, it doesn’t actually need to be there

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh OK! Could you update this PR to remove it then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve removed those calls in Host.swift though I would hold off removing them elsewhere because it could inadvertently introduce memory bugs if the type isn’t absolutely a trivial type and will never be anything but a trivial type in the future

self._storage = UnsafeMutableRawPointer.allocate(bytes: self._typeInfo.size, alignedTo: 1)
self._storage.copyBytes(from: value, count: self._typeInfo.size)
self._storage = UnsafeMutableRawPointer.allocate(byteCount: self._typeInfo.size, alignment: 1)
self._storage.copyMemory(from: value, byteCount: self._typeInfo.size)
Copy link
Contributor

@ianpartridge ianpartridge Oct 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one doesn't read as an improvement to me - the previous API seemed quite clear as to what it would do. Maybe you are fixing some overloading of the meaning of count: though? I'm not sure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was discussed heavily during the review of SE-0184. The core team felt strongly that it should be copyMemory and byteCount.

Copy link
Contributor

@ianpartridge ianpartridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you link me to SE-0184a - I couldn't find it?

Please take my comments as a non-expert's comment to the proposal not this PR per se. Hopefully seeing how someone who has not been immersed in the discussions reacts when confronted with the changes is interesting.

@tayloraswift
Copy link
Member Author

SE 184
SE 184a

@alblue
Copy link
Contributor

alblue commented Oct 10, 2017

@swift-ci please test

@swiftlang swiftlang deleted a comment from tayloraswift Oct 10, 2017
@tayloraswift
Copy link
Member Author

you have to test against the swift PR

@alblue
Copy link
Contributor

alblue commented Oct 11, 2017

@swift-ci please test

1 similar comment
@alblue
Copy link
Contributor

alblue commented Oct 13, 2017

@swift-ci please test

@alblue
Copy link
Contributor

alblue commented Oct 13, 2017

The errors in the build are:

Foundation/AffineTransform.swift:317:55: error: incorrect argument labels in call (have 'byteCount:alignment:', expected 'bytes:alignedTo:')
        let pointer = UnsafeMutableRawPointer.allocate(byteCount: MemoryLayout<Float>.stride * 6, alignment: 1)
                                                      ^~~~~~~~~~                                  ~~~~~~~~~
                                                       bytes                                      alignedTo

@tayloraswift
Copy link
Member Author

tayloraswift commented Oct 14, 2017

@alblue This PR will only build if you build it with the actual compiler modifications in @12200

@alblue
Copy link
Contributor

alblue commented Oct 16, 2017

OK, so when swiftlang/swift#12200 is merged then we can revisit this request

@ianpartridge
Copy link
Contributor

ianpartridge commented Oct 16, 2017

Although SE-184 has been accepted, this PR seems to be for SE-184a - I'm not sure how that relates?

@Kelvin13 will SE-184a require a separate Swift Evolution review cycle? Is this PR dependent on another Swift Evolution proposal beyond SE-184?

If so, I don't think we should keep this PR open for potentially months while that process proceeds. We should close it and reopen it when it's ready. The evolution proposal can link to the closed PR in the meantime.

Thoughts?

@tayloraswift
Copy link
Member Author

@ianpartridge SE-184a is SE-184, SE-184b will likely get a completely different Swift evolution number. It’s confusing I know. Originally it was all one proposal, it got split up in review.

@ianpartridge
Copy link
Contributor

Oh great, thanks for clarifying! In that case, as SE-184 is Accepted we should keep this open.

Do you have an estimate of when you hope to land the implementation of SE-184 into master?

@tayloraswift
Copy link
Member Author

ask @atrick it could be as early as today if we can get the @availableity sorted out

@ianpartridge
Copy link
Contributor

Great. By the way, this needs rebasing as it has a conflict now.

@tayloraswift
Copy link
Member Author

done

@alblue
Copy link
Contributor

alblue commented Nov 10, 2017

@Kelvin13 has SE-184 landed in Swift yet, and if so, can this be merged? If not, do you have a link for the PR in swift that is blocking this PR?

@atrick
Copy link
Contributor

atrick commented Nov 18, 2017

This is being blocked by swiftlang/swift#12200

@atrick atrick merged commit 1b12e83 into swiftlang:master Nov 18, 2017
slavapestov added a commit to slavapestov/swift-corelibs-foundation that referenced this pull request Nov 18, 2017
This reverts commit 1b12e83, reversing
changes made to c13b850.
slavapestov added a commit that referenced this pull request Nov 18, 2017
Revert "Merge pull request #1247 from kelvin13/se-0184a"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants